package com.github.butid.data.netty.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleStateEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author wangjing.dc@qq.com
 * @since 2020/8/3
 */
@Component
@Slf4j
public class HeartbeatHandler extends ChannelInboundHandlerAdapter {


    public HeartbeatHandler(){
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        if(evt instanceof IdleStateEvent){
            IdleStateEvent event = (IdleStateEvent) evt;
            log.debug("{}超时类型:{}", ctx.channel().remoteAddress(), event.state().name());
        }else{
            super.userEventTriggered(ctx, evt);
        }

    }


}
